using QFramework;
using UnityEngine;

namespace ProjectSurvivor
{
    public abstract class PowerUp : GameplayObject
    {
        public bool FlyingToPlayer { get; set; }
		private int FlyingToPlayerFrameCount=0;//飞行至玩家帧数
        protected abstract void Execute();
        private void Update()
        {
			if(FlyingToPlayer)
			{
				if(FlyingToPlayerFrameCount==0)
				{
					//设置渲染顺序 值越大，渲染越靠前 值越小，渲染越靠后 默认0
					GetComponent<SpriteRenderer>().sortingOrder=5;
				}
				FlyingToPlayerFrameCount++;
				if(Player.Default)
				{
					var direction=Player.Default.DirectionFrom(this);
					var distance=direction.magnitude;
					//反方向移动
					if(FlyingToPlayerFrameCount<=15)
					{
						transform.Translate(direction.normalized*-2*Time.deltaTime);
					}
					else//朝玩家移动
					{
						transform.Translate(direction.normalized*7.5f*Time.deltaTime);
					}
					if(distance<0.1f)
					{
						Execute();
					}
				}

			}
            
        }
        protected override Collider2D Collider2D => throw new System.NotImplementedException();
    }
}